import request from "@/utils/request.js"

/**
 * 分页查询用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const queryUserPage = (data) => {
  return request.post('/admin/user/page', data)
}

/**
 * 通过id查询用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const queryUserById = (data) => {
  return request.get('/admin/user/' + data)
}

/**
 * 新增用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const saveUser = (data) => {
  return request.post('/admin/user', data)
}

/**
 * 删除用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const removeUser = (data) => {
  return request.delete('/admin/user', {data})
}

/**
 * 更新用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updateUser = (data) => {
  return request.put('/admin/user', data)
}

/**
 * 重置用户密码
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const resetUserPwd = (data) => {
  return request.put('/admin/user/password/' + data)
}

/**
 * 查询在线用户
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const queryOnlineUser = () => {
  return request.get('/admin/user/online')
}

/**
 * 下线用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const offlineUser = (data) => {
  return request(
    {
      url: '/admin/user/offline',
      method: 'post',
      params: {
        token: data
      }
    }
  )
}

/**
 * 更新用户状态
 * @param id
 * @param data
 * @returns {*}
 */
export const updateUserStatus = (id, data) => {
  return request(
    {
      url: '/admin/user/status/' + id,
      method: 'post',
      params: {
        status: data
      }
    }
  )
}

/**
 * 查询用户数量
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const queryUserNums = () => {
  return request.get('/admin/user/nums')
}

/**
 * 导出用户表格
 */
export const exportUser = (data) => {
  return request.post('/admin/user/export', data, { responseType: 'blob' })
}
